package managedBean.search;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.model.SelectItem;

import controller.search.SearchController;
import dto.search.ProfileDTO;
import dto.search.SearchDTO;

@ManagedBean(name = "searchManagedBean")
@ViewScoped
public class SearchManagedBean {

	private String id;
	private String tenantId = "8P2";
	private ProfileDTO profile;
	private SearchDTO searchDTO;
	@ManagedProperty(value = "#{searchController}")
	private SearchController searchController;
	private List<ProfileDTO> profileList = new ArrayList<ProfileDTO>();
	private String gender;
	private int minAge;
	private int maxAge;
	private int minHeight;
	private int maxHeight;
	private List<SelectItem> heightList;
	private String occupation;
	private List<String> occupationList;
	private int income;
	private List<SelectItem> incomeList;
	private boolean withPhoto;
	private boolean withHoroscope;
	public SearchManagedBean() {

	}

	@PostConstruct
	public void init() {
		gender = "F";
		minAge = 23;
		maxAge = 28;
		minHeight = 121;
		maxHeight = 213;
		initializeHeightList();
		searchDTO = new SearchDTO();
		initializeOccupationList();
		initializeIncomeList();
		withPhoto=false;
		withHoroscope=false;
	}

	private void initializeHeightList() {
		heightList = new ArrayList<SelectItem>();
		heightList.add(new SelectItem(121, "4ft - 121 cm"));
		heightList.add(new SelectItem(124, "4ft 1in - 124cm"));
		heightList.add(new SelectItem(127, "4ft 2in - 127cm"));
		heightList.add(new SelectItem(129, "4ft 3in - 129cm"));
		heightList.add(new SelectItem(132, "4ft 4in - 132cm"));
		heightList.add(new SelectItem(134, "4ft 5in - 134cm"));
		heightList.add(new SelectItem(137, "4ft 6in - 137cm"));
		heightList.add(new SelectItem(139, "4ft 7in - 139cm"));
		heightList.add(new SelectItem(142, "4ft 8in - 142cm"));
		heightList.add(new SelectItem(144, "4ft 9in - 144cm"));
		heightList.add(new SelectItem(147, "4ft 10in - 147cm"));
		heightList.add(new SelectItem(149, "4ft 11in - 149cm"));
		heightList.add(new SelectItem(152, "5ft - 152cm"));
		heightList.add(new SelectItem(154, "5ft 1in - 154cm"));
		heightList.add(new SelectItem(157, "5ft 2in - 157cm"));
		heightList.add(new SelectItem(160, "5ft 3in - 160cm"));
		heightList.add(new SelectItem(162, "5ft 4in - 162cm"));
		heightList.add(new SelectItem(165, "5ft 5in - 165cm"));
		heightList.add(new SelectItem(167, "5ft 6in - 167cm"));
		heightList.add(new SelectItem(170, "5ft 7in - 170cm"));
		heightList.add(new SelectItem(172, "5ft 8in - 172cm"));
		heightList.add(new SelectItem(175, "5ft 9in - 175cm"));
		heightList.add(new SelectItem(177, "5ft 10in - 177cm"));
		heightList.add(new SelectItem(180, "5ft 11in - 180cm"));
		heightList.add(new SelectItem(182, "6ft - 182cm"));
		heightList.add(new SelectItem(185, "6ft 1in - 185cm"));
		heightList.add(new SelectItem(187, "6ft 2in - 187cm"));
		heightList.add(new SelectItem(190, "6ft 3in - 190cm"));
		heightList.add(new SelectItem(193, "6ft 4in - 193cm"));
		heightList.add(new SelectItem(195, "6ft 5in - 195cm"));
		heightList.add(new SelectItem(198, "6ft 6in - 198cm"));
		heightList.add(new SelectItem(200, "6ft 7in - 200cm"));
		heightList.add(new SelectItem(203, "6ft 8in - 203cm"));
		heightList.add(new SelectItem(205, "6ft 9in - 205cm"));
		heightList.add(new SelectItem(208, "6ft 10in - 208cm"));
		heightList.add(new SelectItem(210, "6ft 11in - 210cm"));
		heightList.add(new SelectItem(213, "7ft - 213cm"));
	}

	private void initializeOccupationList() {
		occupationList = new ArrayList<String>();
		occupationList.add("Occupation 1");
		occupationList.add("Occupation 2");
		occupationList.add("Occupation 3");
		occupationList.add("Occupation 4");
	}

	private void initializeIncomeList(){
		incomeList=new ArrayList<SelectItem>();
		incomeList.add(new SelectItem(0,"Any"));
		incomeList.add(new SelectItem(50000,"Rs. 50 K"));
		incomeList.add(new SelectItem(100000,"Rs.1 Lakh"));
		incomeList.add(new SelectItem(200000,"Rs.2 Lakh"));
		incomeList.add(new SelectItem(300000,"Rs.3 Lakh"));
		incomeList.add(new SelectItem(400000,"Rs.4 Lakh"));
		incomeList.add(new SelectItem(500000,"Rs.5 Lakh"));
		incomeList.add(new SelectItem(600000,"Rs.6 Lakh"));
		incomeList.add(new SelectItem(700000,"Rs.7 Lakh"));
		incomeList.add(new SelectItem(800000,"Rs.8 Lakh"));
		incomeList.add(new SelectItem(900000,"Rs.9 Lakh"));
		incomeList.add(new SelectItem(1000000,"Rs.10 Lakh"));
		incomeList.add(new SelectItem(12000000,"Rs.12 Lakh"));
		incomeList.add(new SelectItem(14000000,"Rs.14 Lakh"));
		incomeList.add(new SelectItem(16000000,"Rs.16 Lakh"));
		incomeList.add(new SelectItem(18000000,"Rs.18 Lakh"));
		incomeList.add(new SelectItem(20000000,"Rs.20 Lakh"));
		incomeList.add(new SelectItem(25000000,"Rs.25 Lakh"));
		incomeList.add(new SelectItem(30000000,"Rs.30 Lakh"));
		incomeList.add(new SelectItem(35000000,"Rs.35 Lakh"));
		incomeList.add(new SelectItem(40000000,"Rs.40 Lakh"));
		incomeList.add(new SelectItem(45000000,"Rs.45 Lakh"));
		incomeList.add(new SelectItem(50000000,"Rs.50 Lakh"));
		incomeList.add(new SelectItem(60000000,"Rs.60 Lakh"));
		incomeList.add(new SelectItem(70000000,"Rs.70 Lakh"));
		incomeList.add(new SelectItem(80000000,"Rs.80 Lakh"));
		incomeList.add(new SelectItem(90000000,"Rs.90 Lakh"));
		incomeList.add(new SelectItem(100000000,"Rs.1 Crore"));
		
	}
	public void search() {
		// profile = new ProfileDTO(
		// "1",
		// "mahesh",
		// "Boangiri",
		// "dd/mm/yyyy",
		// "job",
		// "https://scontent-b-sin.xx.fbcdn.net/hphotos-xpa1/t31.0-8/1075318_574073522687896_26281572_o.jpg",
		// "http://www.youtube.com/v/XGSy3_Czz8k");
		try {
			profile = searchController.searchByID(Integer.parseInt(id),
					tenantId);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public List<String> occupationAutoComplete(String query) {
		List<String> results = new ArrayList<String>();
		for (String str : occupationList) {
			if (str.toUpperCase().contains(query.toUpperCase())) {
				results.add(str);
			}
		}
		return results;
	}

	public void basicSearch() {
		searchDTO.setTenantID("8P2");
		searchDTO.setGender(getGender());
		searchDTO.setMinHeight(getMinHeight());
		searchDTO.setMaxHeight(getMaxHeight());
		//searchDTO.setMinAge(getMinAge());
		//searchDTO.setMaxAge(getMaxAge());
		searchDTO.setOccupation(getOccupation());
		searchDTO.setIncome(getIncome());
		searchDTO.setWithPhoto(isWithPhoto());
		searchDTO.setWithHoroscope(isWithHoroscope());
		try {
			profileList = searchController.searchByQuery(searchDTO);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		System.out.println("Occupation 3".contains("occu"));
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public ProfileDTO getProfile() {
		return profile;
	}

	public void setProfile(ProfileDTO profile) {
		this.profile = profile;
	}

	/**
	 * @return the tenantId
	 */
	public String getTenantId() {
		return tenantId;
	}

	/**
	 * @param tenantId
	 *            the tenantId to set
	 */
	public void setTenantId(String tenantId) {
		this.tenantId = tenantId;
	}

	/**
	 * @return the searchController
	 */
	public SearchController getSearchController() {
		return searchController;
	}

	/**
	 * @param searchController
	 *            the searchController to set
	 */
	public void setSearchController(SearchController searchController) {
		this.searchController = searchController;
	}

	/**
	 * @return the searchDTO
	 */
	public SearchDTO getSearchDTO() {
		return searchDTO;
	}

	/**
	 * @param searchDTO
	 *            the searchDTO to set
	 */
	public void setSearchDTO(SearchDTO searchDTO) {
		this.searchDTO = searchDTO;
	}

	public List<ProfileDTO> getProfileList() {
		return profileList;
	}

	public void setProfileList(List<ProfileDTO> profileList) {
		this.profileList = profileList;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public int getMinAge() {
		return minAge;
	}

	public void setMinAge(int minAge) {
		this.minAge = minAge;
	}

	public int getMaxAge() {
		return maxAge;
	}

	public void setMaxAge(int maxAge) {
		this.maxAge = maxAge;
	}

	/**
	 * @return the minHeight
	 */
	public int getMinHeight() {
		return minHeight;
	}

	/**
	 * @param minHeight
	 *            the minHeight to set
	 */
	public void setMinHeight(int minHeight) {
		this.minHeight = minHeight;
	}

	/**
	 * @return the maxHeight
	 */
	public int getMaxHeight() {
		return maxHeight;
	}

	/**
	 * @param maxHeight
	 *            the maxHeight to set
	 */
	public void setMaxHeight(int maxHeight) {
		this.maxHeight = maxHeight;
	}

	/**
	 * @return the heightList
	 */
	public List<SelectItem> getHeightList() {
		return heightList;
	}

	/**
	 * @param heightList
	 *            the heightList to set
	 */
	public void setHeightList(List<SelectItem> heightList) {
		this.heightList = heightList;
	}

	/**
	 * @return the occupation
	 */
	public String getOccupation() {
		return occupation;
	}

	/**
	 * @param occupation
	 *            the occupation to set
	 */
	public void setOccupation(String occupation) {
		this.occupation = occupation;
	}

	/**
	 * @return the occupationList
	 */
	public List<String> getOccupationList() {
		return occupationList;
	}

	/**
	 * @param occupationList the occupationList to set
	 */
	public void setOccupationList(List<String> occupationList) {
		this.occupationList = occupationList;
	}

	/**
	 * @return the income
	 */
	public int getIncome() {
		return income;
	}

	/**
	 * @param income the income to set
	 */
	public void setIncome(int income) {
		this.income = income;
	}

	/**
	 * @return the incomeList
	 */
	public List<SelectItem> getIncomeList() {
		return incomeList;
	}

	/**
	 * @param incomeList the incomeList to set
	 */
	public void setIncomeList(List<SelectItem> incomeList) {
		this.incomeList = incomeList;
	}

	/**
	 * @return the withPhoto
	 */
	public boolean isWithPhoto() {
		return withPhoto;
	}

	/**
	 * @param withPhoto the withPhoto to set
	 */
	public void setWithPhoto(boolean withPhoto) {
		this.withPhoto = withPhoto;
	}

	/**
	 * @return the withHoroscope
	 */
	public boolean isWithHoroscope() {
		return withHoroscope;
	}

	/**
	 * @param withHoroscope the withHoroscope to set
	 */
	public void setWithHoroscope(boolean withHoroscope) {
		this.withHoroscope = withHoroscope;
	}
	
}
